package com.zby.lease.web.admin.service.imp;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zby.lease.model.pojo.SystemPost;
import com.zby.lease.web.admin.mapper.SystemPostMapper;
import com.zby.lease.web.admin.mapper.SystemUserMapper;
import com.zby.lease.model.pojo.SystemUser;
import com.zby.lease.web.admin.service.SystemUserService;
import com.zby.lease.web.admin.vo.system.user.SystemUserItemVo;
import com.zby.lease.web.admin.vo.system.user.SystemUserQueryVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @description 针对表【system_user(员工信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser>
        implements SystemUserService {
    @Autowired
    private SystemUserMapper systemUserMapper;
    @Autowired
    private SystemPostMapper systemPostMapper;
    @Override
    public IPage<SystemUserItemVo> pageUserInfoByQuery(IPage<SystemUserItemVo> page, SystemUserQueryVo queryVo) {
        return systemUserMapper.pageUserInfoByQuery(page, queryVo);
    }

    @Override
    public SystemUserItemVo getSystemById(Long id) {
        // 根据ID查询系统用户信息
        SystemUser systemUser = systemUserMapper.selectById(id);

        // 根据系统用户中的岗位ID查询岗位信息
        SystemPost systemPost = systemPostMapper.selectById(systemUser.getPostId());

        // 创建一个系统用户项的视图对象，用于封装用户信息及岗位名称
        SystemUserItemVo systemUserItemVo = new SystemUserItemVo();

        // 将系统用户信息复制到视图对象中
        BeanUtils.copyProperties(systemUser,systemUserItemVo);
        // 设置用户对应的岗位名称
        systemUserItemVo.setPostName(systemPost.getName());
        return systemUserItemVo;
    }
}




